<?php

namespace App\Services;

use App\Exceptions\AppException;
use App\Models\Setting;
use Illuminate\Support\Facades\DB;

class SettingService
{

    public function getSetting()
    {
        $setting = Setting::first();

        if (!$setting) {
            throw new AppException('配置项丢失');
        }

        return $setting;
    }

    public function getMysqlVersion()
    {
        $data = DB::selectOne('SELECT VERSION() AS version');
        return $data->version;
    }

    public function update(array $data)
    {
        $setting = $this->getSetting();
        $setting->fill($data);
        $setting->save();
    }

}
